package ibg;

class Solution {
	public int solution(int[] A)
	{
	    int N = A.length;
	    if (N < 1) return 0;

	    int max = 0;
	    int result = 0;

	    for(int i = N-1; i >= 0; --i)
	    {
	        if(A[i] > max)
	            max = A[i];

	        int tmpResult = max - A[i];        
	        if(tmpResult > result)
	            result = tmpResult;
	    }

	    return result;
	}

}
